package com.supersit.greensproject.collection;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

/**
 * 管理所有的activity
 * Created by 刘威 on 2015/11/4.
 */
public class ActivityCollection {
    private List<Activity> activities = new ArrayList<Activity>();
    private static ActivityCollection ourInstance = new ActivityCollection();

    public static ActivityCollection getInstance() {
        return ourInstance;
    }

    private ActivityCollection() {
    }

    /**
     * 加入容器
     * @param activity
     */
    public void addActivity(Activity activity){
        if(activity == null) return;
        activities.add(activity);
    }

    /**
     * 从容器中删除
     * @param activity
     */
    public void removeActivity(Activity activity){
        if(activity == null) return;
        activities.remove(activity);
    }

    /**
     * 退出
     */
    public void finishAll(){
        for(Activity activity : activities){
            activity.finish();
//            activities.remove(activity);
        }
        //退出程序
        android.os.Process.killProcess(android.os.Process.myPid());
        System.exit(1);
    }
}
